﻿Shader "Custom/BasicDiffuse" {  
    Properties {  
		//声明变量，在Inspector界面可修改
		_EmissiveColor("Emissive Color",Color)=(1,1,1,1)
		_AmbientColor  ("Ambient Color", Color) = (1,1,1,1)  
		_MySliderValue ("This is a Slider", Range(0, 10)) = 2.5 
    }  
    SubShader {  
        Tags { "RenderType"="Opaque" }  
        LOD 200  
          
        CGPROGRAM  
		//"#pragma surface"将直接告诉Shader使用哪个光照模型用于计算
        #pragma surface surf BasicDiffuse    //此处有两种光照模型
		//声明一个和Properties中名字相同的变量，这将自动建立一个连接，两者将操作同一个数据。
        float4 _EmissiveColor;  
        float4 _AmbientColor;  
        float _MySliderValue;   
  
        struct Input {  
            float2 uv_MainTex;  
        };  
  
		//光照模型一
        void surf (Input IN, inout SurfaceOutput o) {  
            float4 c;
			//http://developer.download.nvidia.com/CgTutorial/cg_tutorial_appendix_e.html  //CG内置函数
			c = pow((_EmissiveColor+_AmbientColor),_MySliderValue);
			o.Albedo = c.rgb;
			o.Alpha = c.a;
        } 
		//光照模型二：自定义光照模型：Lighting<自定义的光照模型名称>
		inline float4 LightingBasicDiffuse (SurfaceOutput s, fixed3 lightDir, fixed atten)  
		{  
			//http://developer.download.nvidia.com/CgTutorial/cg_tutorial_appendix_e.html  //CG内置函数
			float difLight = max(0, dot (s.Normal, lightDir));  
			float4 col;  
			col.rgb = s.Albedo * _LightColor0.rgb * (difLight * atten * 2);  
			col.a = s.Alpha;  
			return col;  
		}
 
        ENDCG  
    }   
    FallBack "Diffuse"  
}  